package com.itheima.bean.processor;

import com.itheima.bean.dao.UserDao;
import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DaoFactoryBean implements FactoryBean<UserDao> {
    public UserDao getObject() throws Exception {
        Object instance = Proxy.newProxyInstance(
                DaoFactoryBean.class.getClassLoader(),
                new Class[]{UserDao.class},
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("简单实现了");
                        return null;
                    }
                }
        );


        return (UserDao) instance;
    }

    public Class<?> getObjectType() {
        return UserDao.class;
    }

    public boolean isSingleton() {
        return true;
    }
}
